home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 001 / hello / hello.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  5KB  |  150 lines

  1. /*
  2.  * Article 27 of net.micro.amiga:
  3.  * ion: version B 2.10.2 9/17/84 chuqui version 1.9 3/12/85; site unisoft.UUCP
  4.  * Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site topaz.RUTGERS.EDU
  5.  * Path: unisoft!dual!lll-crg!seismo!columbia!topaz!eric
  6.  * From: eric@topaz.RUTGERS.EDU (Eric Lavitsky)
  7.  * Newsgroups: net.micro.amiga
  8.  * Subject: Hello World
  9.  * Message-ID: <3529@topaz.RUTGERS.EDU>
  10.  * Date: 4 Sep 85 20:12:41 GMT
  11.  * Date-Received: 5 Sep 85 16:38:36 GMT
  12.  * Organization: Rutgers Univ., New Brunswick, N.J.
  13.  * Lines: 145
  14.  * 
  15.  * Hi,
  16.  * 
  17.  *  Well here is the first ever Amiga source to be posted on the net. The
  18.  * following code was taken from the Amiga User Interface Manual. This
  19.  * program uses the Intuition user interface under V28 of the operating
  20.  * system. Intuition controls all the window sizing and dragging for the
  21.  * application, though you can tell Intuition to tell your program about
  22.  * certain events (like resizing) so you can take your own action. The
  23.  * code is not ultimately clean - all the structures could be initialized 
  24.  * like the first one etc. I kept most of the original comments from the
  25.  * example and added one or two of my own.
  26.  * 
  27.  *  The program opens its own screen (320x200) and creates a window that
  28.  * can be dragged, sized, pushed up or down and closed. The screen can also
  29.  * be pushed down or popped up and be pulled down to reveal the screen below
  30.  * it (one of my favorite features!)
  31.  * 
  32.  * Enjoy!
  33.  * 
  34.  */
  35.  
  36. /***************************************************************************
  37.  *
  38.  *       "Hello World"
  39.  *
  40.  **************************************************************************/
  41.  
  42. #include <exec/types.h>
  43. #include <intuition/intuition.h>
  44. #include <intuition/intuitionbase.h>
  45.  
  46. struct IntuitionBase *IntuitionBase;
  47. struct GfxBase *GfxBase;
  48.  
  49. #define INTUITION_REV 28    /* You must be sure this is correct */
  50. #define GRAPHICS_REV 28
  51.  
  52. /* This font declaration will be used for our new screen */
  53.  
  54. struct TextAttr MyFont =
  55.    {
  56.    "topaz.font",     /* Font Name *
  57.    TOPAZ_SIXTY,      /* Font Height */
  58.    FS_NORMAL,        /* Style */
  59.    FPF_ROMFONT       /* Preferences */
  60.    };
  61.  
  62. /* This is the declaration of a pre-initialized NewScreen data block.
  63.  * It often requires less work, and often uses less code space, to
  64.  * pre-initialize data structures in this fashion.
  65.  */
  66.  
  67. struct NewScreen NewScreen =
  68.    {
  69.    0,                /* the LeftEdge should be equal to zero */
  70.    0,                /* TopEdge */
  71.    320,              /* Width (lo-resolution) */
  72.    200,             /* Height (non-interlace) */
  73.    2,             /* Depth (16 colors will be available) */
  74.    0, 1,             /* the DetailPen and BlockPen specifications */
  75.    NULL,             /* no special display modes */
  76.    CUSTOMSCREEN,     /* the Screen Type */
  77.    &MyFont,          /* Use my own font */
  78.    "My Own Screen",  /* this declaration is compiled as a text pointer */
  79.    NULL,             /* no special Screen Gadgets */
  80.    NULL              /* no special Custom BitMap */
  81.    };
  82.  
  83. main()
  84. {
  85.    struct Screen *Screen;
  86.    struct NewWindow NewWindow;
  87.    struct Window *Window;
  88.  
  89.    /* Open the Intuition library. The result returned by this call is
  90.     * used to connect your program to the actual Intuition routines
  91.     * in ROM. If the result of this call is zero, something is wrong
  92.     * and the Intuition you requested is not available, so your program
  93.     * should exit immediately
  94.     */
  95.  
  96.    IntuitionBase = (struct IntuitionBase *)
  97.       OpenLibrary("intuition.library",INTUITION_REV);
  98.    if(IntuitionBase == NULL)
  99.       exit(FALSE);
  100.  
  101.    GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",GRAPHICS_REV);
  102.    if(GfxBase == NULL)
  103.       exit(FALSE);
  104.  
  105.    if((Screen = (struct Screen *) OpenScreen(&NewScreen)) == NULL)
  106.       exit(FALSE);
  107.  
  108.    /* Initialize the NewWindow structure for the call to OpenWindow() */
  109.  
  110.    NewWindow.LeftEdge = 20;
  111.    NewWindow.TopEdge = 20;
  112.    NewWindow.Width = 300;
  113.    NewWindow.Height = 100;
  114.    NewWindow.DetailPen = 0;
  115.    NewWindow.BlockPen = 1;
  116.    NewWindow.Title = "A Simple Window";
  117.    NewWindow.Flags = WINDOWCLOSE | SMART_REFRESH | ACTIVATE
  118.       | WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH;
  119.    NewWindow.IDCMPFlags = CLOSEWINDOW;    /* Tell us about CLOSEWINDOW events */
  120.    NewWindow.Type = CUSTOMSCREEN;
  121.    NewWindow.FirstGadget = NULL;
  122.    NewWindow.CheckMark = NULL;
  123.    NewWindow.Screen = Screen;
  124.    NewWindow.BitMap = NULL;
  125.    NewWindow.MinWidth = 100;
  126.    NewWindow.MinHeight = 25;
  127.    NewWindow.MaxWidth = 32767;
  128.    NewWindow.MaxHeight = 32767;
  129.  
  130.    /* Try to open the window. Like the call to OpenLibrary(), if
  131.     * the OpenWindow call is successful, it returns a pointer to
  132.     * the structure for your new window. If the OpenWindow() call
  133.     * fails, it returns a zero.
  134.     */
  135.  
  136.    if(( Window = (struct Window *) OpenWindow(&NewWindow)) == NULL)
  137.       exit(FALSE);
  138.  
  139.    Move(Window->RPort,20,20);
  140.    Text(Window->RPort,"Hello World",11);
  141.  
  142.    for(;;)
  143.      {
  144.      Wait(1 << Window->UserPort->mp_SigBit);
  145.      CloseWindow(Window);    /* Close the Window */
  146.      CloseScreen(Screen);    /* Close the Screen */
  147.      exit(TRUE);        /* Exit */
  148.      }
  149. }
  150.